package com.hlbspringcloud.mq;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * @Author huanglibin
 * @Project mq
 * @Description MQ连接工具类
 * @Date 2020-12-02-14-56-38
 * @Version 1.0
 */
public class RabbitmqUntil {

    /**
     * 获取连接
     * @return
     * @throws Exception
     */
    public static Connection getRabbitmqConnection() throws Exception{
        //定义连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        //设置服务地址
        factory.setHost("192.168.65.129");
        //设置端口(这里的端口号指定是AMQP协议所用的端口号)
        factory.setPort(5672);
        //设置数据库
        factory.setVirtualHost("test");
        //设置用户名
        factory.setUsername("test");
        //设置密码
        factory.setPassword("test");
        return factory.newConnection();
    }
}
